package com.qf.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qf.mapper.DtsOrderMapper;
import com.qf.pojo.DtsOrder;
import com.qf.service.DtsOrderService;
import com.qf.vo.DayStatis;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * @version 1.0
 * @auther Administrator
 * @date 2023/2/22 16:29
 */
@Service
public class DtsOrderServiceImpl implements DtsOrderService {
    @Autowired
    private DtsOrderMapper dtsOrderMapper;
    @Override
    public List<DayStatis> findDayStatis() {
        return dtsOrderMapper.findDayStatis();
    }

    @Override
    public long getCount() {
        QueryWrapper<DtsOrder> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("deleted",false);
        return dtsOrderMapper.selectCount(queryWrapper);
    }

    /**
     * 订单管理查看
     * @param userId
     * @param orderSn
     * @param sort
     * @param order
     * @param page
     * @param limit
     * @return
     */
    @Override
    public IPage<DtsOrder> findListByQuery(Integer userId, String orderSn, Integer orderStatus, String sort, String order, Integer page, Integer limit) {
        return dtsOrderMapper.selectPage(new Page<DtsOrder>(page,limit)
                ,new QueryWrapper<DtsOrder>()
                        .eq(!StringUtils.isEmpty(userId),"user_id",userId)
                        .eq(!StringUtils.isEmpty(orderSn),"order_sn",orderSn)
                        .eq(!StringUtils.isEmpty(orderStatus),"order_status",orderStatus)
                        .orderBy(!StringUtils.isEmpty(sort),"ASC".equalsIgnoreCase(order),sort)
        );
    }

    @Override
    public DtsOrder detail(DtsOrder dtsOrder) {
//        dtsOrderMapper.findDetail(dtsOrder);
        return dtsOrder;
    }


}
